﻿
#region Usings
using System;
#endregion

namespace LongNet.Util.DataTypes
{
    /// <summary>
    /// Class designed to replace List. Contains events so that we can tell
    /// when the list has been changed.
    /// </summary>
    public class List<T> : System.Collections.Generic.List<T>
    {
        #region Events
        public EventHandler<ChangedEventArgs> Changed;
        #endregion

        #region Public Functions

        public new void Add(T value)
        {
            base.Add(value);
            ChangedEventArgs TempArgs = new ChangedEventArgs();
            TempArgs.Content = PropertyName;
            EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
        }

        public new void AddRange(System.Collections.Generic.IEnumerable<T> value)
        {
            base.AddRange(value);
            ChangedEventArgs TempArgs = new ChangedEventArgs();
            TempArgs.Content = PropertyName;
            EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
        }

        public new bool Remove(T obj)
        {
            bool ReturnValue = base.Remove(obj);
            ChangedEventArgs TempArgs = new ChangedEventArgs();
            TempArgs.Content = PropertyName;
            EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
            return ReturnValue;
        }

        public new void RemoveAt(int index)
        {
            base.RemoveAt(index);
            ChangedEventArgs TempArgs = new ChangedEventArgs();
            TempArgs.Content = PropertyName;
            EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
        }

        public new int RemoveAll(Predicate<T> match)
        {
            int ReturnValue = base.RemoveAll(match);
            ChangedEventArgs TempArgs = new ChangedEventArgs();
            TempArgs.Content = PropertyName;
            EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
            return ReturnValue;
        }

        public new void RemoveRange(int index, int count)
        {
            base.RemoveRange(index, count);
            ChangedEventArgs TempArgs = new ChangedEventArgs();
            TempArgs.Content = PropertyName;
            EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
        }

        public new void Insert(int index, T value)
        {
            base.Insert(index, value);
            ChangedEventArgs TempArgs = new ChangedEventArgs();
            TempArgs.Content = PropertyName;
            EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
        }

        public new void InsertRange(int index, System.Collections.Generic.IEnumerable<T> collection)
        {
            base.InsertRange(index, collection);
            ChangedEventArgs TempArgs = new ChangedEventArgs();
            TempArgs.Content = PropertyName;
            EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
        }

        public new void Clear()
        {
            base.Clear();
            ChangedEventArgs TempArgs = new ChangedEventArgs();
            TempArgs.Content = PropertyName;
            EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
        }

        #endregion

        #region Properties

        public new T this[int index]
        {
            get { return base[index]; }
            set
            {
                base[index] = value;
                EventHelper.Raise<ChangedEventArgs>(Changed, this, new ChangedEventArgs());
            }
        }

        public string PropertyName { get; set; }

        #endregion
    }
}